using TickSharp.Core;
using TickSharp.Core.Exceptions;
using TickSharp.Core.Interfaces;
using TickSharp.DependencyResolution;
using Xunit;

namespace TickSharp.Tests.UnitTests
{
    public class IoCTester
    {
        public IoCTester()
        {
            IoC.Reset();
        }

        [Fact]
        public void ResolverThrowsExceptionWhenNullResolverRequested()
        {
            Assert.Throws(typeof (NotInitializedException), () => IoC.Resolver);
        }

        [Fact]
        public void ResolverReturnsResolverWhenResolverPassedIn()
        {
            IDependencyResolver dependencyResolver = new DependencyResolver();
            IoC.Initialize(dependencyResolver);
            IDependencyResolver resolver = IoC.Resolver;

            Assert.Equal(dependencyResolver, resolver);
        }

        [Fact]
        public void DuplicateInitializationThrows()
        {
            IDependencyResolver dependencyResolver = new DependencyResolver();
            IoC.Initialize(dependencyResolver);
            
            Assert.Throws(typeof(DuplicateInitializationException), () => IoC.Initialize(dependencyResolver));
        }
    }
}